// pages/article/comment/comment.js
import CommunityModule from '../../../../models/3.0/community'

Component({
  /**
   * Component properties
   */
  options: {
    addGlobalClass: true
  },
  properties: {
    newUserId:{
      type: String
    },
    replyCommentNickName:{
      type: String
    },
    userId:{
      type: String
    },
    Id:{
      type: String
     },
    __id: {
      type: String
    },
    _id: {
      type: String
    },
    content: {
      type: String
    },
    avatar: {
      type: String
    },
    date: {
      type: String
    },
    name: {
      type: String
    },
    like: {
      type: String
    },
    isPraise: {
      type: Boolean
    },
   
    children: {
      type: Array,
      value: []
    }
  },

  data: {
    newName:'',
    id:'',
  },

  methods: {
    reply(e) {
      console.log('replyCommentNickName',this.data.replyCommentNickName);
      this.setData({
        newName:e.detail.name,
        id:this.data._id
      })
      this.triggerEvent('reply', {
        name: this.data.name,
        id: this.data._id,
        newName:e.detail.name,
        type:this.data.__id
      })
      wx.setStorageSync('__ID', this.data.__id)
    },
    like() {
      if(this.data.isPraise===false){
        CommunityModule.momentLike({
          id: this.data._id||this.data.__id,
          momentID:this.data.Id,
          type: 1
        }).then(res=>{
          this.setData({
            isPraise:true,
            like:+(this.data.like)+1
          })
        })
      } else{
        CommunityModule.noMomentLike({
          id: this.data._id||this.data.__id,
          type: 1,
          momentID:this.data.id
        }).then(res=>{
          this.setData({
            isPraise:false,
            like:+(this.data.like)-1
          })
        })
      } 
    }
  }
})
